
layui.use(['element','table','layer','form'], function(){
	var table = layui.table;
	var layer = layui.layer;
	var form=layui.form
		, $ = layui.jquery;
	util = layui.util;

	table.render({
		elem: '#basicParamTable',
		height: 'full-150',
		url:  "/basicSysParam/paramTable", //数据接口
		method: 'post',
		request:{
			page: 'pageNum', //页码的参数名称，默认：page
			limit: 'pageSize' //每页数据量的参数名，默认：limit
		},
		where: {
			blockName: ""
		},
		page: true, //开启分页
		cols: [[ //表头
			{type:'numbers'}
			,{field: 'acsSysParamId', title: 'ID',width:180,align:'center' }
			,{field: 'paramKey', title: '参数键值',width:120,align:'center' 	}
			,{field: 'paramName', title: '参数名称',width:120,align:'center' }
			,{field: 'paramVal', title: '参数值',width:130, align:'center' }
			,{field: 'paramInfo', title: '参数信息',width:120, align:'center'  }
			,{field: 'createTime', title: '添加时间',width:170, align:'center',templet: function (d) {
					return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss");
				}    }
			, {field: 'right', title: '操作', align:'center',width:200,templet:function(data){
					var op = '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
					op+='<a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>';
					return op;
				}
			}
		]]

	});

	//添加系统信息
	addParam = function () {
		$("#block_up").hide();
		$("#block_form").show();
		$("#block_form").attr("disabled", false);
		$("#block_form").attr("class", "layui-btn");
		$("#product_form")[0].reset();
		layer.open({
			type: 1
			, title: '新增'
			, shadeClose: true
			, area: ['500px', '80%']
			, content: $('#paramAdd')
		});
	};

	//操作列
	table.on('tool(basicParamTable)', function(obj){
		var data = obj.data;
		if(obj.event === 'delete'){
			layer.confirm('是否确认删除'+data.paramName+'的信息？', {
				btn: ['确认', '返回'] //按钮
			}, function () {
				$.post('/basicSysParam/delParamInfo',{pid:data.acsSysParamId},function (res) {
					if(res.resultCode === '000'){
						layer.msg('删除成功',{
							time:500,
							end:function () {
								table.reload('basicParamTable')
							}
						})
					}else{
						layer.msg(res.resultDesc);
					}
				})
			})
		}else if (obj.event === 'edit'){
			$("#block_up").show();
			$("#block_form").hide();
			$("#block_up").attr("disabled", false);
			$("#block_up").attr("class", "layui-btn");
			form.val('product_form',{
				'acsSysParamId': data.acsSysParamId,
				'paramKey': data.paramKey,
				'paramName':data.paramName,
				'paramVal':data.paramVal,
				'paramInfo': data.paramInfo,
			});
			form.render();
			layer.open({
				type: 1
				, title: '编辑信息'
				, shadeClose: true
				, area: ['500px', '80%']
				, content: $('#paramAdd')
			});
		}
	});

	//提交系统信息表单
	form.on('submit(block_form)',function(data){
		$("#block_form").attr("disabled", true);
		$("#block_form").attr("class", "layui-btn layui-btn-disabled");
		var inFun = 0;
		layer.confirm('是否确认提交系统信息？', {
			btn: ['确认', '返回'] //按钮
		}, function () {
			if(inFun === 1){
				return;
			}
			inFun = 1;
			$.post("/basicSysParam/addParamInfo", data.field, function (data) {
				if(data.resultCode === "000"){
					layer.closeAll();
					layer.msg('提交成功',{
						time:500,
						end:function () {
							table.reload('basicParamTable')
						}
					})
				}else{
					layer.msg( data.resultDesc );
				}
			})
		}, function () {
			layer.closeAll();
			return false;
		});
		return false;//返回false 防止二次提交
	})

	//更新系统信息
	form.on('submit(block_up)',function(data){
		$("#block_up").attr("disabled", true);
		$("#block_up").attr("class", "layui-btn layui-btn-disabled");
		var inFun = 0;
		layer.confirm('是否确认更新系统信息？', {
			btn: ['确认', '返回'] //按钮
		}, function () {
			if(inFun === 1){
				return;
			}
			inFun = 1;
			$.post("/basicSysParam/upParamInfo", data.field, function (data) {
				if(data.resultCode === "000"){
					layer.closeAll();
					layer.msg('更新成功',{
						time:500,
						end:function () {
							table.reload('basicParamTable')
						}
					})
				}else{
					layer.msg( data.resultDesc );
				}
			})
		}, function () {
			layer.closeAll();
			return false;
		});
		return false;//返回false 防止二次提交
	})

})

function reload(){
	location.reload();
}